<?php
/*
 * Created on 2016/11/26
 * 修改用户信息
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 session_start();
 require_once('../db/properties.inc.php');
 require_once("../service/InsertUser.class.php");
 require_once("../entity/user.inc.php");
 	
 $userInfo = $_SESSION["userInfo"]; 
 $userObj = json_decode($userInfo);//用户信息
 if(!$userInfo){
 	header("Location: ../../view/login.html");
 	exit;
 }
 
 $mind = $_POST["mind"];
 $provinces = $_POST["provinces"];
 $city = $_POST["city"];      
 $passwd=$_POST["passwd"];
 $emails=$_POST["email"];
 $nowDate =  date('Y-m-d H:i:s',time());
 $loginUser = $userObj->userName;
 
 //保存用户头像
 try {
 	 $conn = new mysqli($url, $user, $pwd, $dbname, $port);
	 $conn -> set_charset("utf8");
	 if (mysqli_connect_errno()) {
	 	echo "0";
	    exit;
	 }
	 $sql = "UPDATE userInfo SET ";
	 if(!empty($passwd)){
	 	$sql .= " passwd='".md5($passwd)."',";
	 }
	 if(!empty($emails)){
	 	$sql .= " email='".$emails."',";
	 }
	  if(!empty($mind)){
	 	$sql .= " mind='".$mind."',";
	 }
	  if(!empty($provinces)){
	 	$sql .= " provinces='".$provinces."',";
	 }
	  if(!empty($city)){
	 	$sql .= " city='".$city."',";
	 }
	 
	 $sql .= " updateTime='".$nowDate."' WHERE id=".$userObj->id;
	 $conn->query($sql);
	 $conn->close();
	 
 	 $user = new InsertUser();
 	 $result = $user -> queryUsers($loginUser);//获取用户信息
 	 $_SESSION["userInfo"]=$result;
	 
	 echo "1";
	 exit;
 }catch( Exception $e ) {
 	 echo "0";
 	 exit;
 }
    
?>
